<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column label="编号" align="center" prop="id" width="50"/>
      <el-table-column label="赛事名称" align="center" prop="eventName"/>
      <el-table-column label="赛项名称" align="center" prop="competitionName" />
      <el-table-column prop="stageCurrent" label="阶段" width="100" align="center">
        <template #default="scope">
          <dict-tag :options="sys_race_stageCurrent" :value="scope.row.stageCurrent" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新日期" align="center" prop="updateTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime,"{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isActive">
        <template #default="scope">
          <dict-tag :options="sys_log_isActive" :value="scope.row.isActive" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 查看日志详情 -->
    <el-dialog :title="title" v-model="open" width="1200px" append-to-body>
      <el-table :data="form" height="250" style="width: 100%">
        <el-table-column type="index" label="编号" width="50" align="center"/>
        <el-table-column prop="eventName" label="赛项名称" width="120"  align="center"/>
        <el-table-column prop="competitionName" label="赛事名称" width="120" align="center"/>
        <el-table-column prop="raceType" label="比赛方式" width="120" align="center"/>
        <el-table-column prop="track" label="赛道" width="120" align="center"/>
        <el-table-column prop="organizers" label="主办方" width="120" align="center"/>
        <el-table-column prop="creator" label="修改人" width="120" align="center"/>
        <el-table-column prop="version" label="版本" width="100" align="center"/>
        <el-table-column prop="stageCurrentStatus" label="状态" width="100" align="center">
          <template #default="scope">
            <dict-tag :options="sys_log_isActive" :value="scope.row.isActive" />
          </template>
        </el-table-column>
        <el-table-column prop="stageCurrent" label="阶段" width="100" align="center">
          <template #default="scope">
            <dict-tag :options="sys_race_stageCurrent" :value="scope.row.stageCurrent" />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="160">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新日期" align="center" prop="updateTime" width="160">
          <template #default="scope">
            <span>{{ parseTime(scope.row.updateTime,"{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="160" align="center"/>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Post">
import {listlog , getlog} from "@/api/contestment/_approlog"
import Log from "@/views/monitor/job/log.vue";
const { proxy } = getCurrentInstance();
const { sys_log_isActive , sys_event_value,sys_race_type,sys_track_type,sys_race_stageCurrent} = proxy.useDict("sys_log_isActive","sys_event_value","sys_race_type","sys_track_type","sys_race_stageCurrent");

// const isShow = ref(false)
const logList = ref([]);
const open = ref(false);
const loading = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const form = ref([])
const data = reactive({
  queryParams: {
    pageNo: 1,
    pageSize: 10,
  }
});

const { queryParams } = toRefs(data);
/**获取日志列表*/
function  getList(){
  loading.value = true;
  listlog(queryParams.value).then(response=>{
    logList.value = response.data.result
    if(logList.value!=null){
      for(const item of logList.value){
        if(item.stageCurrentStatus===3){
          item.isActive=2
        }else if(item.stageCurrentStatus===2){
          item.isActive=true
        }else if(item.stageCurrentStatus===4){
          item.isActive=1
        }
      }
    }
    total.value = response.data.total
    loading.value = false
  })
}
/**查看详情*/
function handleUpdate(row) {
  console.log(row)
  getlog(row.relation,row.stageCurrent).then(response=>{
    form.value = response.data.result
    for(const item of form.value){
      if(item.stageCurrentStatus===3){
        item.isActive=2
      }else if(item.stageCurrentStatus===2){
        item.isActive=true
      }else if(item.stageCurrentStatus===4){
        item.isActive=1
      }
    }
    open.value = true
    title.value = "日志详情"
  })
}
/**取消按钮*/
function cancel(){
  open.value = false
}
getList();
</script>
